package com.fzu.express.controller;


import com.fzu.express.annotation.SystemLog;
import com.fzu.express.entity.Outlet;
import com.fzu.express.service.OutletService;
import com.fzu.express.utils.PageVO;
import com.fzu.express.utils.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zyq
 * @since 2022-10-27
 */
@RestController
@RequestMapping("/outlet")
public class OutletController {
    @Resource
    private OutletService outletService;

    @GetMapping
    public R list(Outlet outlet, @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                  @RequestParam(required = false, defaultValue ="10") Integer pageSize){
        PageVO pageVO = outletService.listOutlet(outlet, pageNum, pageSize);
        return R.ok().data(pageVO);
    }

    @PostMapping
    @SystemLog(businessName = "新增快递网点")
    public R add(@RequestBody Outlet outlet){
        outletService.addOutlet(outlet);
        return R.ok();
    }

    @PutMapping
    @SystemLog(businessName = "更新快递网点")
    public R update(@RequestBody Outlet outlet){
        outletService.updateOutlet(outlet);
        return R.ok();
    }

    @DeleteMapping("/{id}")
    @SystemLog(businessName = "删除快递网点")
    public R delete(@PathVariable("id") Long id){
        outletService.deleteOutlet(id);
        return R.ok();
    }
}

